<?php
/**
 * 路由类
 * User: Administrator
 * Date: 2019/4/2
 * Time: 11:35
 */
namespace core\lib;
use core\lib\conf;
class route
{
    public $ctrl;
    public $action;

    public function __construct()
    {
        if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != explode('index.php',$_SERVER['SCRIPT_NAME'])[0]) {
            $tmp_path = explode('/index.php',$_SERVER['SCRIPT_NAME']);
            $path = explode($tmp_path[0],$_SERVER['REQUEST_URI']);
            $pathArr = explode('/',trim($path[1],'/'));
            if (isset($pathArr[0])) {
                $this->ctrl = ucfirst($pathArr[0]);
            }
            unset($pathArr[0]);
            if (isset($pathArr[1])) {
                $this->action = $pathArr[1];
                unset($pathArr[1]);
            } else {
                $this->action = conf::get('ACTION','route');
            }
            $count = count($pathArr) + 2;
            $i = 2;
            while ($i < $count) {
                if (isset($pathArr[$i + 1])) {
                    $_GET[$pathArr[$i]] = $pathArr[$i + 1];
                }

                $i = $i + 2;
            }
        } else {
            $this->ctrl = ucfirst(conf::get('CTRL','route'));
            $this->action = conf::get('ACTION','route');
        }
    }
}